package com.dwjm.shop.HSh.utils;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectionDatabaseForMySQLUseJdbc {
//    连接数据库的驱动

//    private static final String DRIVER="com.mysql.cj.jdbc.Driver";
    private static final String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
//    连接数据库的URL
//    private static final String URL="jdbc:mysql://localhost:3306/9_Group?&useSSL=false%serverTimezone=Asia/Shanghai";
    private static final String URL = "jdbc:sqlserver://124.221.132.179:1433;databaseName=9_Group";
    //    连接数据库的账号
    private static final String USER="sa";
//    连接数据库的密码
    private static final String PASSWORD="9342567897jbp";
//    连接数据库对象
    static Connection connection=null;
//    定义数据库的函数
    public static Connection getConnection(){
        try {
            Class.forName(DRIVER);
            connection = DriverManager.getConnection(URL,USER,PASSWORD);
            return connection;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
//    测试数据库是否连接
    public static void main(String[] args) {
        System.out.println(getConnection()==null);  //true
    }
}
